<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>修改备注</title>
		<link rel="stylesheet" type="text/css" href="lib/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="css/yaopin.css" />
		<style type="text/css">
			.search {
				display: block;
			}
		</style>

	</head>
	<body>
		<a href="javascript:history.go(-1)">返回</a>
		<h3>药品管理 修改备注</h3>
		<hr>
		<form class="layui-form search" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">药品名称:</label>
				<div class="layui-input-block">
					<input type="text" name="itemName" autocomplete="off" class="layui-input" readonly unselectable="on">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">拼音简码:</label>
				<div class="layui-input-block">
					<input type="text" name="searchText" autocomplete="off" class="layui-input" readonly unselectable="on">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">药品类型:</label>
				<div class="layui-input-block">
					<input type="text" name="itemClassName" autocomplete="off" class="layui-input" readonly unselectable="on">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">药品单位:</label>
				<div class="layui-input-block">
					<input type="text" name="itemSpec" autocomplete="off" class="layui-input" readonly unselectable="on">
				</div>
			</div>
			<!-- <div class="layui-form-item">
				<label class="layui-form-label">药品类型:</label>
				<div class="layui-input-block">
					<select name="city" lay-verify="">
						<option value=""></option>
						<option value="26503">普通</option>
						<option value="26505">高危</option>
						<option value="26504">中危</option>
					</select>
				</div>
			</div> -->
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">药品备注：</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容" name="notes" class="layui-textarea"></textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn save" lay-submit="" lay-filter="ypbz">保存</button>
				</div>
			</div>
		</form>
	</body>
	<script src="lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/global.js" type="text/javascript" charset="utf-8"></script>

	<script type="text/javascript">
		layui.use(['form', 'laytpl'], function() {
			var layer = layui.layer,
				$ = layui.jquery,
				form = layui.form,
				laytpl = layui.laytpl;

			var id = "2"

			var val = GetRequest();
			console.log(val);
			id = val.id;

			function GetRequest() {
				var url = location.search; //获取url中"?"符后的字串
				console.log(url);
				var theRequest = new Object();
				if (url.indexOf("?") != -1) {
					var str = url.substr(1);
					strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			}

			function drugdetail(id) {
				var param = JSON.stringify({
					"body": {
						"drugId": id
					},
					"header": {},
					"token": {}
				})
				$.ajax({
					'type': 'post',
					'url': '/service-nursing/drug/info',
					'data': param,
					'dataType': 'json',
					'contentType': "application/json",
					'success': function(data) {
						console.log(data);
						var d = data.data;
						for (k in d) {
							// console.log(k, d[k]);
							$("input[name=" + k + "]").val(d[k]);
							$("textarea[name=" + k + "]").val(d[k]);
						}
					},
					'error': function(res) {
						console.log(res);
					}
				});
			}
			drugdetail(id)


			// 修改提交
			form.on('submit(ypbz)', function(data) {
				console.log(data.field.notes);

				var note = data.field.notes;
				var update = JSON.stringify({
					"body": {
						"drugId": id,
						"notes": note
					},
					"header": {},
					"token": {}
				})
				$.ajax({
					'type': 'post',
					'url': '/service-nursing/drug/updateNotes',
					'data': update,
					'dataType': 'json',
					'contentType': "application/json",
					'success': function(data) {
						console.log(data);
						if (data.status === 0) {
							layer.msg('保存成功');
						}
					},
					'error': function(res) {
						console.log(res);
					}
				});

				return false;
			});
		})
	</script>
</html>
